<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>class方式绑定计算属性和方法</title>
  <script type="text/javascript" src="vue.js"></script>
  <style>
    div>div {
      width: 60px;
      height: 60px;
      border: 2px solid #bbb;
      text-align: center;
      line-height: 60px;
      font-size: 30px;
      margin:10px;
      float:left;
    }
    .selected{
      border-color: #000;
    }
    .active{
      background: #bbb;
    }
  </style>    
</head>
<body>
  <div id="app">
    <div v-bind:class="randomComputed">1</div>
    <div v-bind:class="randomComputed">2</div>
    <div v-bind:class="randomMethod()">3</div>
    <div v-bind:class="randomMethod()">4</div>
  </div>

  <script>
    function randomBool(){
      return Boolean(Math.round(Math.random()));
    }
    var vm = new Vue({
      el: '#app',
      data:{
        div1:{selected: false, active: false},
        div2:{selected: true, active: false},
        div3:{selected: false, active: true},
        div4:{selected: true, active: true},
      },
      computed:{
        randomComputed(){
          return {selected: randomBool(), active: randomBool()}
        }
      },
      methods:{
        randomMethod(){
          return {selected: randomBool(), active: randomBool()}
        }
      }  
    })
  </script>
</body>
</html>